/*
 * gtype.h
 *
 *  Created on: Dec 5, 2011
 *      Author: Kylin Tse
 */

#ifndef GTYPE_H_
#define GTYPE_H_

#include <QtCore>

typedef struct _tParamEthernet
{
	QString mac;
	QString ip;
	QString netmask;
}ParamEthernet;

typedef struct _tParamSerial
{
	QString bitrate;
	QString charbits;
	QString stopbits;
	qint32 parity;
}ParamSerial;

enum PVType
{
	pvtAi=1,
	pvtDi=2,
	pvtPi=3,
	pvtDo=4,
	pvtction=5,
	pvtAlarm=6,
	pvtAo=7,
};

typedef struct _tParamDevice
{
	quint32 id;
	QString type;

	QList<qint32> lstAi;
	QList<qint32> lstDi;
	QList<qint32> lstPi;
	QList<qint32> lstDo;
	QList<qint32> lstAo;
	QList<qint32> lstAction;
	QList<qint32> lstAlarm;
}ParamDevice;

typedef struct _tParamHy103Cpu
{
	quint32 devId;
	qint8 needAnalysis;
	QList<qint32> lstAi;
	QList<qint32> lstDi;
	QList<qint32> lstPi;
	QList<qint32> lstDo;
	QList<qint32> lstAo;
	QList<qint32> lstAction;
	QList<qint32> lstAlarm;
}ParamHy103Cpu;

typedef struct _tParamDeviceProtocol
{
	quint32 id;
	QString type;
	QString devNode;
}ParamDeviceProtocol;


typedef struct _tValuePrecision
{
	quint32 intDigits;
	quint32 decimalDigits;
}ValuePrecision;

typedef struct _tValueRange
{
	float minValue;
	float maxValue;
	float valueStep;
}ValueRange;

typedef struct _tBatEvent
{
	quint32 code;
	quint32 timeOccur;
}BatEvent;

typedef struct _tBatteryStatus
{
	quint32 voltage;
	quint32 volHigh;
	quint32 volLow;
	qint32 current;
	quint32 tempAvg;
	quint32 tempHigh;
	quint32 tempLow;
	quint32 capRemain;
	quint32 volMol1;
	quint32 volMol2;
	quint32 volMol3;
	quint32 volMol4;
	quint32 volMol5;
	quint32 volMol6;
	quint32 volMol7;
	quint32 volMol8;
	quint32 volMol9;
	quint32 volMol10;
	quint32 volMol11;
	quint32 volMol12;
	quint32 tempMol1;
	quint32 tempMol2;
	quint32 tempMol3;
	quint32 tempMol4;
	quint32 tempCharge;
	quint32 volChargeGlobe;
	quint32 alarm;

	quint32 curCof1;
	quint32 curCof0;
	quint32 tempCof1;
	quint32 tempCof0;

	quint32 volMol1Cof;
	quint32 volMol2Cof;
	quint32 volMol3Cof;
	quint32 volMol4Cof;
	quint32 volMol5Cof;
	quint32 volMol6Cof;
	quint32 volMol7Cof;
	quint32 volMol8Cof;
	quint32 volMol9Cof;
	quint32 volMol10Cof;
	quint32 volMol11Cof;
	quint32 volMol12Cof;

	QList<quint16> lstChnnlCof;
	QList<quint8> lstDiValue;
	QList<BatEvent> lstEvent;

	quint8 powerAC1;
	quint8 powerAC2;

	quint8 chnnlCofWrite;					// 0x01 write
											// 0x02 stop update

	QString desc;
	QStringList lstMesureChnnlDesc;
	QStringList lstChnnlDesc;
	QStringList lstChnnlDimension;
	QList<ValuePrecision> lstChnnlPrecision;
	QList<ValueRange> lstChnnlRange;
	QList<qint16> lstMesureValue;
	QStringList lstAlarmDesc;
	QMutex lock;
}BatteryStatus;

#define U16_LO8(a) (quint8)(a)
#define U16_HI8(a) (quint8)((quint16)((a)&0xFF00)>>8)

#define U8_TO_U16(hi,lo) ((quint16)(hi)*0x100+(quint16)(lo))

#endif /* GTYPE_H_ */
